Memory and code optimizations