refactor flash handling