Check for nil, fix bug