Note that I added a simplify call here compared to the original PR. Necessary?