Refactored to support latest API changes.