add better error handling