refactor getCategory function