Better hook handling
Fixed variable reference