cleaning up and reorganizing some of the javascript