moving logging statements around and adding a condition for html replacement