Some refactor and add format test.