improved demo code