Fixed bugs

Fixed an import and detecting an error.
Merge pull request #1 from suedadam/master

Fixed bugs