added try / catch blocks for the file I/O