adding code initially done in JSFiddle