Upgraded factory and demo code to make it more 'event based'