Fixed memcpy bug and merges common changes