more performance improvements and a fixed test case