Refactored to avoid duplication