refine logic