Fixed Search Algorithm Bug