many changes (please see test.cc)