refactoring some javascript and some other clean up