Refactored and fixed failing tests