reorganize formatter code into a class