some javascript refactorings