memory and speed optimizations