Added better error handling so stacktraces of fatal errors are recorded
on file.