Cleanup and exception handling