changed handling undefined cells; added cell clipping