Overhauled output to allow json and plain csv formats.