fixing python implementation