Refactored detection