javascript refactoring completed