Refactor monad runner in python