refactor bytearray copying, make it easier to be optimized by compiler