code refactoring: js methods