Re-add error checking that I accidentally removed