modified to not use let-binding for intermediary var