changed hooks to run at more appropriate times