refact some method and add test case