Revised code, with the main filter working!!!