Added a null check to prevent anomalous crash.