refactor js (again, again, again +1)