Added Sam's changes to original code