change some code around for future compatability with python 3