refactored.
refactored.
fixed JSON API and test cases.