Restructure code to pass jslint