Partial refactor of transform_expectations

TODO: move responsibility to another module