Refactor js into file structure