optimizations

Made some optimizations for cpp targets: now it should run much faster (at least it's so on my PC)