Refactor logic to run hooks into a function

This is the first step towards arbitrary hook packages.