port over some of the old code