Bug fix/ota flash reliability

Needs to be tested before merging with master