Restructuring the javascript.