Fixed flash-write edge-cases

Not sure why it doesn't work still...
Before adding lots of test things…..