Most functions essentially implemented, not tested.