fix python2.6 compat and refacto per as @Adonoho's #201