Refactored helper functions