Refactor based on new tests