Lots of cleanup and small fixes.