Improved py3 compatibility