reworked the python code, now simpler