small refactoring of demo code