Completed refactoring of js