final pass and refactor, much more DRY