added try,catch for file opening