refactor js code into new file