check for file existence first, more efficient