Some performance issues fixes

Large test cases' performance is still very bad. :confused: