Improve error management
Close #93
Fix #138, #89