Refactor of login system