Rewrite the comment posts generation to eliminate duplicate code