refactor common code into DefaultFormatter

refactor common code into DefaultFormatter