JS bug (Guess I should have used Haskell here)