Fixes for a couple of logic bugs.