refactor of js