Refine UI logic for mainform.