Improving javascript code using requirejs