more error handling and cleanup