memcpy bugfixes + optimizations