Extracted method run_hooks to take care of copy pasted code in the before/after hooks