Refactor js into separate file