Improve error reporting and cleanup
This branch improves the messages produced when various errors occur (i.e. makes those messages clearer), and cleans up the code in a few areas
This branch improves the messages produced when various errors occur (i.e. makes those messages clearer), and cleans up the code in a few areas