Rewrite code with Maybe monad.

There is no more presumption that some func will return Just x.