Refactoring some extension code