Refactoring into functions