Code updated with amendments from PR comments.