Begin refactoring of js