refactor & optimize demo2