optimize code and testcase