Rewriting a few chunks in order to ensure sanitization of output and less code duplication