Fix bug in applyAttributes function