code updated in order to avoid hitting the service more than once