refine client control flow