fixed python implementation