Fix compile errors and use CPP for TH