Cleaning up the javascript, adding logging, etc