added in Jeremy's changes. Fixed scope.