added the logout logic
fixed a bug of logout

move some scripts in the main form to a new file