Refactor, improved detection