Better test for roots.
Move code for finding roots into the Stack class.

This makes it easier for Stratopan to reuse.