Code optimizations. Now ~240% faster!