Fixed error handling

Added distinction between fatal and nonfatal errors and improved their
handling.
Changed error handling

Removed unnecessary assertations and replaced with better exception
handling. API reading function in progress.