WIP Fix 251: Improve error handling

Fix #251