Refactored reformatter to make it easier to read.