Add ts mode setting and some cleanup