Fixed some JavaScript bugs