moved the file exists check