improved error handling a bit