almost done.

todo: dim repeated lines. cleanup.