adding legacy code, and some tests failing due to unknown global effects.