Tweaks to key cleanup methods, added a test.