A few bug fixes in logging in and closing.