Working on algo and implementation