fixed bugs in Python version