Move hooks to allow proper unit tests

Unaltered functionality + test