Documentation of the code with tests, small refactoring