Added code to ensure no loops occur in the Category model