Move code from topic controller to model