Fixing filtering code