register and login refactored