Refactor functions into separate file