adjusted error handling