beefing up error handling a bit