Made code to be compatible with Python 2