Refactoring: Move all fork handling into a higher-order function

C++11 lambdas ftw.