def snake_to_camel(name):
    """Convert snake case names to camel case with first word capitalzed.
    Always capitalizes first letter (to handle camel case starting with
    lower case).  Preserves one leading underscore if present."""
    leading_underscore = False
    if name and name[0] == "_":
        leading_underscore = True
    name = name[0].upper() + name[1:]
    words = name.split("_")
    if len(words) == 1 or (len(words) == 2 and leading_underscore):
        return name
    cap_words = [w.capitalize() for w in words]
    joined_name = "".join(cap_words)
    if leading_underscore:
        joined_name = "_" + joined_name
    return joined_name