Updated to work with latest API changes.