second algorithm v2 changed