improoved error handling