Unite the `transpose` implementations reducing code duplication