Remove redundant source code and improve test cases