Cleanup and made compatible with latest API