cleaned up query code, support media library filter