Improved add error markup function, condensed to use less code.