re-factoring topic code