In the code-review branch... In END_OF_TRANSMISSION, if flashPointer = offset is on a page boundary, I think the page needs to be erased as in FLASH_DATA.