Original Python version
New improved JavaScript version