Fixed an error in filtering algorithm