Added comments and JSON formatting option to format function.