Add plan tests and fix a bug found by them