Added login dialog and many bug fixes