Rewrote events and logic separately.