rewriting to cleanup and abstract certain concepts.