some code cleanup and bug fixes

(0) -30 -10 -1 +1 +10 +30 +100 +300 tip

mercurial