Rewriting get_available_name() to handle max_length. Adding test for the case.