Code refactoring: monadic based computation