Modify the filter logic and add filtering for folders