revised to refactor using Sam's test code