Enhance message filtering code