Wrong placement of error handling function

This closes #92