Fix bug in JavaScript