better demo, and organize into smaller functions