Refactored code in category js