fix some issues with json encoding and returned response