Fix potential nil pointer crash