Added a lot of code for directFilter. Needs more testing.