refine and cleanup