error handling improved