separating javascript logic into separate file and a lil code cleanup as well