Optimize tests

Some magic involved.  As a PR for review.