monadic(?) refactoring