Re-inserted error checking code