Fixing window events. Not sure if fully stable.