Add type of operation to stack and refactor.