Refactored and enhanced Tset functions