Cleanup and better logging