Refactoring the demo code to simplify