second adaptation for running on python 3.3 and python 2.7