added better comments throughout
Significant rewrite and reorganization; still in progress