fix building TH, add some TH tests