fixes memory leaks and crashes with FilterData()