Functionnal refactorings

I tried to do many small commit to show the different step to get a more functionnal version of your code.
I can go further if you want.
I can also explain more.