fix printing for python3 and bounds check for python2.6