Fixed bug in Python implementation, added comments to C++ implementation