check if layers are null before changing attributes