Refactor JS application