fixed check for existing files