refactoring and splitting in functions