Restarted from scratch with explicit monad types.