Added check for nil state