Temporarily fix the bug of logout.
Do some improve of exceptional handling.
Add test program.