mprove error handling