Move static functions to util.c they may be used by other sources. Add optional html entity replacement function