Minor code optimizations

I made the main dojojs code a bit lighter and removed some repeated code. General refactoring.