Fixed test case & refactoring