Organizing the mess of JavaScript code