refactoring for triangles