Algorithm breaks bug fixed