Fixed code duplication for file existence checking