Fixed bug in format_entities