added fileFormat parameter and fixed format variable assignment