refractor and testcases