Fixed error handling, closes #34