pasted the main from the tutorial