refactored and fixed unit tests