performance upgrades and code cleanup