First working version with a very simple algorithm