Some other javascript improvements
Refactoring