monad code cleanup; reorg