fix optimization bugs in test