fix style bugs in flattenTerms