first version, abridged from my sand-box framework to be stand-alone