Made the code testable and created a part of the unittests.