refactoring, moving into functions