added second algorithm