Restructure the javascript code a little.