First batch of fixes for py3.