Coded up the recovery logic. No tests yet.