Error handling improved