py3-related fixes

extracted from #365 by @fantix