Introduce proper error handling in several places, and perform a first pass at refactoring Instance to make it easier to use.