I've done some modifications to be compatible with Python3