updated code to work with Python 3