python2 and python3 compatibility (almost)