Make brush detection consistent, fix bugs in generating code tags.