Let's start with the json output correctly tested + a lot of refactoring