python 2.6 AND 3k compat. Misc tidy up.