refactored, using allen's set-up.