While studying this code I noticed a few inconsistencies and possible cleanups. Please consider these patches.