check if sorted terms exist to eliminate PHP notice