First stab at TMS implementation (will be changed).
More work on TMS implementatin.