Adds security check of nil value to avoid crash.