Replaced loop-based matrix copy with memcpy