Refactor forking from main into exec-function