Refactor code and uncomment test case