big fatty refactor -- tests do not pass.