Add null check for class attribute