started refactoring to make opcounting a proper monad