Really should have broken this up, but lots of cleanup