Use a hook instead of the if structure