refactoring test code, fixed a few bugs, CAS