Refactor js into external file