Refactor operators to massively decrease code duplication. Remove history from invert function (not needed).