While lengthy, got the filtering working correctly.