Adding some checks to writePage() to check for corrupted header