fix bugs causing errors in json return