maybe monad and continuation monad refactoring