Memory and algorithm optimizations