Lots of cleanup and a couple small fixes