add Test case, fix lots of bugs. v 0.2