Updated code for Mary's post