Refactored the flash code to use a helper method.