This code smells but works fine, please help us to refactor it. Remember, after refactor the output of this code must be the same. We expect you refactor the code using good practices and apply design patterns, the code must be Clean. Unit tests are mandatory.
Feels free to fork and start to refactor.
Happy coding!