Used memcopy to improve performance