building function fromTRex