finished refactoring flash code