fixed bug in json, some code cleanup