put repetitive code in own functions, decreased size of generateFileName function