Added sorting to the fields before output