fixed categories and redone some loops with filters instead