Updated to allow output to file (DLL/SO) to work -- but segfaults