added validity check upon opening a file