Overall refactoring with added unit tests (3)