start of nicer error handling