refine code according to review comments