performance patches; genral code cleanup