Added null check when determining the next layer color.