refractoring and add test case