fixed some bugs, added filter function.