refactoring javascript backend.