Refactor UI code.