perf improvements and fixes
fix tests