refactoring into functions