much improved performance and memory useage