Fixing numerous small nasty bugs