Feature/issue 661 reimplement error handling

This fixes Issue #661.