fix crash. performance improvements