storing uploaded file in flash; refactoring