Code refactored for Demo2