Second try
Complete rewrite
Applies inversion of control
Changing lists to Data.Sequence
fourth try