login and register code cleanup