improved query for getting only "valid" languages