Fixed some bugs, now works with Python 2.