Major formatting cleanup, with more to come. Tests need fixing.