Put js code into external js file + Minor changes