FINALLY fixed file naming function