Clean filtering utils and improve unit tests