fixed issues with logic for determining file name