Finish the login method. Add some comments. Fix some errors and bugs.