Fixed unit tests and refactored to more rational test structure