Feature/issue 178

Fixes #218 and #178. Basically implements proper error handling and reporting.