replacing while(1) by critical error handling