Reorganize filter query
Fix open/delete logic