improved decode for python 3 compatibility