Code cleanup, and some minor tweaks.