Refactor and update test cases