changed to desired output format, and replaced setdefault with get