Moved file opening into separate function
Changed file opening error to more meaningful one