Refactor `TopicsController` and remove code duplication

Refactor `TopicsController` and remove code duplication