Improved error handling

Relates to / fixes #137 #138 #144