Updated error handling

* Improved error handling where it existed before.
* Correct class & function names in the error strings.
* Removed variable assignments in conditions.
* Refactored implicit type conversions.