added function to extract filename from an entity with error correction in