slightly better error handling