Modified code to reflect the latest API changes.