Base functionality of REquireJs as well as some refactoring