better python 3 legacy code conversion