Total refactor without problems thanks to the tests!