The Canonical Model of a Singular Curve