fix bugs in trimtail