Fix attribute encoding issues. Closes #2644.