python implementation modified