error handling

Improved a little bit of the error handling