Sort of refactor js