complete js refactor