updated for py3 compatibility