Deleted some redundant code
Made login event-driven, and fixed some bugs