Changing to window.addEventListener for improved stability.