File-opening check added