Refactoring and add login