add a better error handling