finished refactoring the flash code