add filtering for fields - code refactored - needs more work