Working impl that needs functional refactoring.

This works, but is highly procedural.  Next step is to
refactor to use a more functional style.  Very little use is
being made of first class functions, etc.