Optimizing IMS filter clause building