error handling improvemnt