add result/error to json, more code cleanup