bug fix in trench code