marked stack overflow borrowed method
added expanatory text