Fixed outdated constant call.
Fixed a bug.
Using json_encode for json api.