code refine & add test case