code is hacked to pieces on cat_detail, but it works