Updated version of the comment formatting logic

Largely rewritten logic for comment formatting with a big focus on properly formatting XML structures.