Base functionality of REquireJs as well as some refactoring

Now using RequireJs!