Speed up and optimizations