#2 refactoring functions