Bunch of error handling stuff, etc.