small improvements to filtering code