refactored to generate file name with the path