refactored flash handling