Added debug code.
Fixed hang on exit when running as Mac App