Updated code as suggested by reviewers.