Add error checking for mismatched block endings