refine and bug fix