refactoring favorite function