Fixed bug in Javascript