Fix and refactor category filter