cleanup and proper error evaluation