refactoring code to be a bit DRYer, fixing bug in topictree rendering.