fix and refactor window event calls