reimplementation in python.
small bugfix