Refactoring Client Side Login Code