improved error handling a little bit