Check if 'topic' exists before trying to access it