Improve error handing