Performance improvements and fixes