code reengineered but not yet tested