Refactored to follow angular-login example