assorted fixes: speed, correctness, ball-of-wax