fixed control flow so function works when file exists