refactoring file response to correctly handle both images and text
minor refactoring