an initial working (at least somewhat) python version of the code