Improved make_valid_nickname function.