Added check to ensure variable is assigned before being used.