TCAPI - code from Jamie Smith - merged for master