Refactor example to include events api