Fix flash

Supersedes pull request #122 . Rebased on master.