Added checks for file existence