Updated to support 2-legged and 3-legged.