Fixed error handling (Fix #142)