Remove unneeded memory allocation and copying