some bug fixes in JS