Fix for performance issues and EXC_BAD_ACCESS crashes