Fixing errors in filtering code