refactor demo code