fixed tests. optimized a bit