Updated broken tests and refactored code