Move hook logic out into its own module