Cleaned up some of the javascript code