Bugfix for flash

(cherry picked from commit 8c3fabaf2d3637896dee4cf3b1306b069d7f9ae7)