Sorry, my code is rather long and inelegant.
I tried to only extract what was useful in the above, below is the entire work in progress :
I tried to only extract what was useful in the above, below is the entire work in progress :
Long and inelegant code