Improving code and test cases