Refactored to reduce code reuse