Cleanup, refactor and fix example security issue