refactored to make it easier to run this under the sandbox.