updated code for entity extraction