initial rev - ported from jsfiddle