Added error handling to login/register