Added checking for file existence.