Fix functions related to attach/detach window