bugs fixed, and performance speed up