code refactore done and test case modified