split javascript into separate file and updated formatting