Unify hook code for in/out.