Reworked errors, added some errors, and various other refactorings.