Major revisions to general code structure. Work in progress.