Complete rework of the code