refactoring the demo