Fixing JS integer overflow problem