UnitTests added / Refactoring to improve testability