Fixes #2 by making the triangle algorithm iterative instead of recursive. However, the effect is still recursive.