update the code from my jsfiddle
revise the relationship between the sm and scratch