cleaned up javascript and fixed some bugs