JavaScript bug fix