Code refactory with unit test.