place logoutandwait function to proper location of the script.