This is a function that does a handful of of independent things... could easily be split up.