added login logic and various fixes.