Major changes.

Redesigned algo.
Added much functionality.