Performance improvements and some cosmetic changes