Add demo2 and refactor some common code.