fixed some bugs. improved filtering