ht.c, unittest.c: code cleanup & bug fixing