first version derived from spiffy's work