reverse engineering the original python code, getting closer...