first version of python implementation