Refactored favorites code