def get_freejoint(element):
  """Retrieves the free joint of a body. Returns `None` if there isn't one."""
  if element.tag != 'body':
    return None
  elif hasattr(element, 'freejoint') and element.freejoint is not None:
    return element.freejoint
  else:
    joints = element.find_all('joint', immediate_children_only=True)
    for joint in joints:
      if joint.type == 'free':
        return joint
    return None