refactoring the functionality for adding categories