code cleanup and minor tweaks