Cleaned up the javascript a bit