Made filter more general
Changed to use standard functionality