refactor js (again)