Fixed Version of Sam's Code