Fixed broken tests and refactored for readability