Refactoring attachment to only run when the window is not already attached.