refactor formatter and add test cases