this needs a lot of cleanup, but start of D&D code port over