Refactored to remove redundant helper functions