Fix some escaping issues.
Move logic into template helpers.