Fix bug in category view controller and reuse code in the view controllers