Refactored code when root category is created (fixes and cleanup)