imporve error handling