Cleanup and restructure of TH code.