code cleanup and controls tweaks