rewrote the whole thing into a framework. Untested