Refactored to simplify writing extensions