Move some operations to properly find the parent window