Corrected code and applied latest API changes.