Code cleanup, misc tweaks