Cleanup and basic error handling