Moved the dereferencing of a window pointer to after the check for its