much refactoring in progress yet, blocks of pseudocode strewn about