rearranged to avoid duplicate triples and better performance