Simplify where implementation

Fixes various bugs... As discussed at length in d265815015fc7b95d90b580e60f569de887fd2c6 and #146