Fix -keepold during master key rollover

This branch contains three commits: a fix for #7995, a test case for #7995, and a partial cleanup of kdb_cpw.c for master.  There are still some cleanup opportunities in kdb_cpw.c after the last commit, but they are relatively minor.