error handling imporoved