fixing inefficiency in file queries