refactor js to separate file