refactor register and login