many tests + optimizations