Move hooks into separate function