Added reference and input file existence checking