Fix beforeClose.