Backported setFlash method changes from master