Fixed JavaScript bugs