Refactor the abtest code.