Modified to cope with API changes.