refactor js into a separate file