Correct error handling
Fix undefined reference
Merge pull request #551 from andrerod/dev

Correct error handling