Improved performance and fixed random crash bug.