Python implementation seems to work after bug fixes