Javascript cleanup and fixes