remove empty entities early in the process, use lambda function for filtering