replicate code from jsfiddle example