Making the code compatible with Python 3