Move persist logic into own package in anticipation of upcoming complexity.

Also cleanup main.go- it was getting far too long.