reorganize demo code