algo optimizations and write performance improvements