Fix for incorrect use of shared ptr references
Cleanup of code that decides whether or not to fork. Fix for issue where stderr may be output twice.