Should probably break these into their own functions to make clearer what failed.