reorgenized ui logic