Big refacto : change algorithm