latest refacoring (compiles, untested)