improve screen closing logic