little speed and memory optimizations