Refactored the profiler hook