refactor code to file