Condensed Sam's code