Refactor UI code structure