Cleanup and updated to the latest api.