trying to add function from jsfiddle