Refactored unit-tests and refactored code a bit