Rearranged and changed some samples to JavaScript