Stuff from jsfiddle, modified to run independently