Structuring data while filtering