updated pad algorithm