Modified code according to latest comments