Refactored web event listener for an invariant in the constructor.