Rewrote hook related code.