fixed hasId() and result sorting