Fixed bug in Triangle function + algebraic simplification.