This PR continues the effort of moving logic inside execution lifecycle hooks into standalone testable functions, as a stepping stone to refactoring the hooks themselves.