Implementation of the demo from CS193p class.