Combine conditionals
Simplify appending CDATA
Use add_attribute method instead of accessing attributes hash