Changed contains algorithm