Detour function and hooks