Bunch of minor tweaks and code cleanup