i think i finnised algortithm