Refactor extend_method to reduce complexity