better error handling for a few cases