quantifier pulling passes tests, but code is hideous