Algorithm fixed