put repetitive code in own functions, decreased size of generateFileName function
fixed a few minor things.