fixes for working under both python 2 and python 3