Fix term sorting