refactor code to methods