improved login and register function