Huge overhall

rewrote most code.  Fully functional now, no bugs.