Refactored code so events are fired automatically