JSON output + code cleanup