Refactoring of polymorphic detection code