refactor triangle