Initial implementation of filtering capabilities
Improve filtering code a bit