speed improvements and fixes