extract and move some ui logic