First draft of the python algorithm