Added checking for existing files