Code cleanup and fix lame test (still lame).