Refactor some logic.