Various minor code clean-ups and upgrades